package com.sneaker.shower.entity.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public enum UserTypeEnum {
    NORMAL(0, "普通用户", BigDecimal.ONE, BigDecimal.ZERO, 0),
    LEVEL_1(1, "普通一级会员", new BigDecimal("0.95"), BigDecimal.valueOf(500), 1),
    LEVEL_2(2, "普通二级会员", new BigDecimal("0.9"), BigDecimal.valueOf(1000), 1),
    LEVEL_3(3, "普通三级会员", new BigDecimal("0.85"), BigDecimal.valueOf(2000), 1),
    LEVEL_4(4, "黑卡一级会员", new BigDecimal("0.8"), BigDecimal.valueOf(5000), 2),
    LEVEL_5(5, "黑卡一级会员", new BigDecimal("0.7"), BigDecimal.valueOf(10000), 2),
//    LEVEL_6(6, "黑卡一级会员", new BigDecimal("0.7"), new BigDecimal("0.01"), 2),
//    LEVEL_7(7, "黑卡一级会员", new BigDecimal("0.7"), new BigDecimal("0.01"), 2),
    ;
    @EnumValue
    private Integer code;
    private String message;
    private BigDecimal discount;
    private BigDecimal price;
    private Integer level;

    UserTypeEnum(Integer code, String message, BigDecimal discount, BigDecimal price, Integer level) {
        this.code = code;
        this.message = message;
        this.discount = discount;
        this.price = price;
        this.level = level;
    }

    public static UserTypeEnum getByCode(Integer code) {
        return Arrays.stream(values()).filter((e) -> e.getCode().equals(code)).findFirst().orElse(null);
    }

    public static UserTypeEnum getByPrice(BigDecimal price) {
        return Arrays.stream(values()).filter((e) -> e.getPrice().equals(price)).findFirst().orElse(null);
    }

    public static List<UserTypeEnum> getByLevel(Integer level) {
        return Arrays.stream(values()).filter((e) -> Objects.equals(e.getLevel(), level)).collect(Collectors.toList());
    }

    public BigDecimal getPrice() {
        return price;
    }

    @JsonValue
    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public BigDecimal getDiscount() {
        return discount;
    }

    public Integer getLevel() {
        return level;
    }
}
